package com.itlaoqi.thread.threadpool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ThreadPoolSample3 {

    public static void main(String[] args) {
        //调度器对象
        //ExecutorService 用户管理线程池
        //守护线程或者顺序执行
        ExecutorService threadPool = Executors.newSingleThreadExecutor();//单线程线程池
        for (int i = 0; i < 1000; i++) {
            final int index = i;
            threadPool.execute(new Runnable() {
                @Override
                public void run() {
                    System.out.println(Thread.currentThread().getName() + ":" + index);
                }
            });
        }
        //shutdown() 代表关闭线程池。等待其他线程完成
        //shutdownNow()
        threadPool.shutdown();
    }
}
